package com.utils
{
	import com.abstract.IWeiboAPI;
	import com.douban.api.DoubanAPI;
	import com.events.WeiboEvent;
	import com.fanfou.api.FanfouAPI;
	import com.sina.microblog.api.WeiboAPI;
	import com.sohu.api.SouhuAPI;
	import com.tencent.weibo.utils.TencentAPI;
	import com.wangyi.api.WangyiAPI;
	
	import flash.events.Event;
	import flash.events.EventDispatcher;
	import flash.events.IOErrorEvent;
	
	public class WeiboManager extends EventDispatcher
	{
		public function WeiboManager()
		{
		}
				
		public function loadAPI(weibo:String,type:String,params:Object):void{
			var weiboAPI:IWeiboAPI;
			switch(weibo){
				case 'fanfou':
					weiboAPI = new FanfouAPI;
					break;
				case 'weibo':
					weiboAPI = new WeiboAPI;
					break;
				case 'tencent':
					weiboAPI = new TencentAPI;
					break;
				case 'wangyi':
					weiboAPI = new WangyiAPI;
					break;
				case 'sohu':
					weiboAPI = new SouhuAPI;
					break;
				case 'douban':
					weiboAPI = new DoubanAPI;
					break;
			}
			(weiboAPI as EventDispatcher).addEventListener(WeiboEvent.RESULT,resultHandler);
			weiboAPI.callWeiboAPI(type,params);
		}
		
		private function resultHandler(event:WeiboEvent):void{
			dispatchEvent(event.clone());
			(event.currentTarget as EventDispatcher).removeEventListener(WeiboEvent.RESULT,resultHandler);
		}
		
	}
}